<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>批量添加智能柜</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
    <div class="mt-5">
        <div class="d-flex justify-content-center">
            <button type="button" onclick="add()" class="btn btn-primary">开始添加</button>
        </div>
    </div>

</body>

</html>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.7/js/bootstrap.min.js"></script>
<script>

    let num = 2;
    function add() {
        if (num === 27) return;
        var myHeaders = new Headers();
        myHeaders.append("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImxvZ2luX3VzZXJfa2V5IjoiM2MyMDg0NmMtZjc2Yy00MDkwLWFiYmQtZThjMjRiMjI5MTcyIn0.ngQbTkIwJA1cu_XeE5QXVOSanMZMGzs7S46owhQFQCXRrAxXms1FtUvS6r-0-hdAJbnZtbscPLvIaAjYs8ierQ");
        myHeaders.append("User-Agent", "Apifox/1.0.0 (https://apifox.com)");
        myHeaders.append("Content-Type", "application/json");
        myHeaders.append("Accept", "*/*");
        myHeaders.append("Host", "localhost");
        myHeaders.append("Connection", "keep-alive");

        let num_ = num;
        if (num < 10) {
            num_ = '0' + num;
        }

        var raw = JSON.stringify({
            "cabinetCode": "2",
            "boxCode": num_,
            "boxName": num_,
            "boxNeiAddr": '192.168.0.' + num_,
            "boxWaiAddr": '192.168.0.1' + num_
        });
        num = num + 1;
        var requestOptions = {
            method: 'POST',
            headers: myHeaders,
            body: raw,
            redirect: 'follow'
        };

        fetch("http://localhost/dev-api/system/cabBox?pageNum=1&pageSize=10", requestOptions)
            .then(response => response.text())
            .then(result => { add() })
            .catch(error => console.log('error', error));
    }

</script>